﻿using System;
using System.Collections;
using System.Data;
using System.Data.OracleClient;
using INTEX.DataBase.Tools;
public static partial class DAILYUPDATE
{
    public static DataSet BatchLoadIntexKeyTable(string option = "LE")
    {
        today = yesterday.Year.ToString() + Right("00" + yesterday.Month.ToString(), 2) + Right("00" + yesterday.Day.ToString(), 2);
        //option is used to get batch data EQ(equal) to today to  LE(less equal) today
        //if request by phone, usuallly it is LE
        //locally, every day can prepare the data by EQ
        OracleCommand cmd = new OracleCommand();
        cmd.CommandType = CommandType.Text;
        cmd.Connection = new OracleConnection("user id=intex;data source=intex1;password=intex;Unicode=True;Persist Security Info=True;");
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        try
        {
            /*result = ReadKDSTAMM(cmd);
            result = ReadVAART(cmd);
            result = ReadVAFARBEN(cmd);
            result = ReadWBDAT(cmd);
            result = ReadGPBST(cmd);            
            result = ReadVKPOS(cmd);
            result = ReadVKKOPF(cmd);            
            result = ReadWASTAMM(cmd);
            result = ReadWAFARBEN(cmd);
            result = ReadWDECK(cmd);
            result = ReadABAUFM(cmd);
            result = ReadABPOS(cmd);
            result = ReadABFOLGE(cmd);
            result = ReadBAAUF(cmd);
            result = ReadGAAUF(cmd);
            result = ReadGSDAT(cmd);
            result = ReadGSCOLOR(cmd);
            result = ReadLIEFDAT(cmd); */
            result = ReadWASTAMM(cmd, "EQ");
            setreturn.Merge(result);
            Upload(new DataSet());
            /* 
             * */
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    public static DateTime tomorrow = DateTime.Now.AddDays(1);
    public static DateTime yesterday = DateTime.Now.AddDays(-1);
    public static string today = "";
    public static string Right(string str, int num)
    {
        try
        {
            int leng = str.Length;
            str = str.Substring(leng - num, num);
        }
        catch (Exception ex)
        {
        }
        return str;
    }
    public static string Left(string str, int num)
    {
        try
        {
            int leng = str.Length;
            str = str + "                                                                                ";
            str = str.Substring(0, num);
        }
        catch (Exception ex)
        {

        }
        return str;
    }
    public static void Upload(DataSet setnotify)
    {
        string file = @"C:\IntexReport\PhoneDB\BatchLoadIntexKeyTable.TOSKY";
        setnotify.WriteXml(file, XmlWriteMode.IgnoreSchema);
 
    }
    public static DataSet GetSkyDriveFileList()
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        try
        {
            string file = @"C:\IntexReport\PhoneDB\SkyFileList.xml";
            if (!System.IO.File.Exists(file))
            {
                //通常会存在
                ReadSkydrive();
            }
            result.ReadXml(file);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        { 
        }
        return setreturn;
    }
    private static void ReadSkydrive()
    {
        try
        {
            DataSet setnotify = new DataSet();
            string file = @"C:\IntexReport\PhoneDB\ReadSkydrive.TOSKY";
            setnotify.WriteXml(file, XmlWriteMode.IgnoreSchema);
        }
        catch (Exception ex)
        { 
        }
    }
 }
 